/*
 * Created: Author: Aléx Carvalho / Date: Jan 23, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-06-11 01:28:43 -0300 (Thu, 11 Jun 2015) $
 */
package com.cpm.entities;

import com.cpm.entities.converters.IndicatorDirectionPersistenceConverter;
import com.cpm.entities.converters.IndicatorModePersistenceConverter;
import com.cpm.entities.converters.IndicatorPeriodicityPersistenceConverter;
import com.cpm.entities.types.IndicatorDirectionType;
import com.cpm.entities.types.IndicatorModeType;
import com.cpm.entities.converters.LocalDatePersistenceConverter;
import com.cpm.entities.types.Family;
import com.cpm.entities.types.IndicatorPeriodicity;
import com.cpm.wrapper.CompetenceList;
import com.cpm.wrapper.Performance;
import com.cpm.wrapper.Position;
import com.cpm.wrapper.Weight;
import java.time.LocalDate;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Transient;

@Entity
public class Indicator extends Node<Indicator> {

    @Embedded
    private Weight weight;

    @Column(length = 8)
    private String units;

    @Column(nullable = false, length = 1)
    @Convert(converter = IndicatorDirectionPersistenceConverter.class)
    private IndicatorDirectionType direction;

    @Column(nullable = false, length = 1)
    @Convert(converter = IndicatorModePersistenceConverter.class)
    private IndicatorModeType mode;

    @Column(nullable = false, length = 2)
    @Convert(converter = IndicatorPeriodicityPersistenceConverter.class)
    private IndicatorPeriodicity periodicity;
    
    @Column(nullable = false)
    @Convert(converter = LocalDatePersistenceConverter.class)
    private LocalDate dtStart;

    @Column(nullable = false)
    @Convert(converter = LocalDatePersistenceConverter.class)
    private LocalDate dtEnd;

    @Transient
    private CompetenceList competenceList;

    public Indicator() {
        competenceList = new CompetenceList(this);
    }

    public Indicator(Integer parentId, Family parentFamily, Weight weight, String units, IndicatorDirectionType direction, IndicatorPeriodicity periodicity, IndicatorModeType mode, User responsible, StrategicPlan strategicPlan, String name, Information information, LocalDate dtStart, LocalDate dtEnd, Position position, Performance performance) {
        this();
        
        this.parentId = parentId;
        this.parentFamily = parentFamily;
        this.weight = weight;
        this.units = units;
        this.direction = direction;
        this.mode = mode;
        this.periodicity = periodicity;
        this.responsible = responsible;
        this.strategicPlan = strategicPlan;
        this.name = name;
        this.information = information;
        this.dtStart = dtStart;
        this.dtEnd = dtEnd;
        this.position = position;
        this.performance = performance;
    }

    public CompetenceList getCompetenceList() {
        return competenceList;
    }
    
    public Weight getWeight() {
        return weight;
    }

    public String getUnits() {
        return units;
    }

    public IndicatorDirectionType getDirection() {
        return direction;
    }

    public IndicatorModeType getMode() {
        return mode;
    }

    public IndicatorPeriodicity getPeriodicity() {
        return periodicity;
    }

    public StrategicPlan getStrategicPlan() {
        return strategicPlan;
    }

    public LocalDate getDtStart() {
        return dtStart;
    }

    public LocalDate getDtEnd() {
        return dtEnd;
    }

    public void setCompetenceList(CompetenceList competenceList) {
        this.competenceList = competenceList;
    }

    @Override
    public Family getFamily() {
        return Family.INDICATOR;
    }

    @Override
    public String toString() {
        return name;
    }

    @Override
    public Indicator clone() {
        Indicator other = new Indicator();
        other.id = id;
        other.parentId = parentId;
        other.parentFamily = parentFamily;
        other.weight = weight;
        other.units = units;
        other.direction = direction;
        other.mode = mode;
        other.periodicity = periodicity;
        other.responsible = responsible;
        other.strategicPlan = strategicPlan;
        other.name = name;
        other.information = information;
        other.dtStart = dtStart;
        other.dtEnd = dtEnd;
        other.position = position;
        other.performance = performance;
        return other;
    }

    public static IndicatorBuilder builder() {
        return new IndicatorBuilder();
    }
}
